package com.tianchi.lexiang.util;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import android.util.Log;


public class SyncDBUtil {
	private static final String TAG = "SyncDBUtil";
	private static SyncDBUtil instance = new SyncDBUtil();
	private FileOutputStream fos;
	private boolean isPrepare = false;
	public static SyncDBUtil getInstance(){
		return instance;
	}
	
	public boolean isPrepare() {
		return isPrepare;
	}

	public void prepareSyncDB(){
		try {
			fos = new FileOutputStream(new File(DBOperator.DB_PATH,DBOperator.DB_NAME));
			isPrepare = true;
			Log.d(TAG, "[prepareSyncDB]prepare  fileoutputstream ");
		} catch (FileNotFoundException e) {
			Log.e(TAG, "[prepareSyncDB]",e);
			e.printStackTrace();
		}
	}
	
	public void writeToFile(byte[] buffer) {
		try {
			fos.write(buffer);
		} catch (IOException e) {
			Log.e(TAG, "[writeToFile]",e);
			e.printStackTrace();
		}
	}
	
	public void close() {
		if (fos != null) {
			try {
				fos.close();
				isPrepare = false;
			} catch (IOException e) {
				Log.e(TAG, "[close]",e);
				e.printStackTrace();
			}
		}
	}
}
